package com.example.xu_li_hua;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class SerializationExample {
    public static void main(String[] args) {
        Person person = new Person("Alice", 25);

        try (FileOutputStream fileOut = new FileOutputStream("person.ser");
             ObjectOutputStream out = new ObjectOutputStream(fileOut)) {
            // 写入对象
            out.writeObject(person);
            System.out.println("对象已序列化并保存到 person.ser 文件中");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}